<?php
load_info_var($cf_controller);	   //加载smarty变量
load_file('order_class', LIB_PATH);
$main = new Order($db);
$id = isset($_POST['id']) ? intval($_POST['id']) : intval($_GET['id']);
$self = isset($_POST['self']) ? trim($_POST['self']) : trim($_GET['self']);
$return_page = $cf_pre_page ? $cf_pre_page : $cf_self_page;

switch ($cf_action) {
    case "index":	
	$smarty->mypage($cf_controller, $cf_action, 0);	
	$skey = isset($_POST['skey']) ? trim($_POST['skey']) : urldecode($_GET['skey']);
	$skey2 = isset($_POST['skey2']) ? trim($_POST['skey2']) : urldecode($_GET['skey2']);
	$skey3 = isset($_POST['skey3']) ? trim($_POST['skey3']) : urldecode($_GET['skey3']);
	$skey4 = isset($_POST['skey4']) ? trim($_POST['skey4']) : urldecode($_GET['skey4']);	
	$where = " order_status = '3' ";
	if ($skey) {
	    $where .= " and order_user like '%" . $skey . "%'";
	}	
	if ($skey2 && $skey3) {
            $where .= " AND DATE_FORMAT(order_rebate_time,'%Y-%m-%d')  BETWEEN '".$skey2."' AND '".$skey3."'";
    }	
	if($skey4){
		$where .= " and order_goods_title like '%" . $skey4 . "%'";
	}		
	if (is_numeric($self)) {
	    $where .= " and order_is_rebate = '" . $self . "'";
	}

	load_file('page_class', LIB_PATH);
	$MyPage = new Mypage($db);
	$field = '*';
	$data_ary = $MyPage->from_sql($field, $main->get_table_name(), $where, "order_id DESC", intval($_GET['cpage']), "20");
	$page = $MyPage->get_page($data, $cf_self_page . '?dpt=' . $cf_dpt . '&skey=' . $skey . '&skey2=' . $skey2 . '&skey3=' . $skey3 . '&skey4=' . $skey4. '&self=' . $self);
	//echo $MyPage->get_sql();
	//dump($data_ary);
	break;   
	case "complete":
		$data['order_rebate_number'] = trim($_POST['order_rebate_number']);
		$data['order_rebate_remark'] = trim($_POST['order_rebate_remark']);		
		$data['order_is_rebate'] = '1';				 
		$data['order_rebate_operator'] = $cf_admin_info['admin_name'];			
		$data['order_rebate_time'] = date("Y-m-d H:i:s");
			    
	    $result = $main->update_data($data, "order_id = '$id'");
	    if ($result) {
			my_page('操作成功!',1);
	    } else {
			my_page('操作失败!',0);
	    }
	
	break;  
    default:
	my_jump('非法操作!');
	break;
}
$smarty->assign(array(
    'id' => $id,
    'row' => htmlchar($row),
    'data_ary' => $data_ary,
    'sessionid' => session_id(),
    'page' => $page,
    'self' => $self,
    'skey' => $skey,
    'skey2' => $skey2,
    'skey3' => $skey3,
    'skey4' => $skey4,
	'cate' => $cate
));
$smarty->mydisplay();
?>